'''
Description: 
Autor: didiplus
Date: 2023-01-13 14:07:09
LastEditors: lin
LastEditTime: 2023-01-13 14:18:04
'''

import concurrent.futures
import cnblogs_spider


#craw 
with concurrent.futures.ThreadPoolExecutor() as pool:
    htmls = pool.map(cnblogs_spider.craw,cnblogs_spider.urls)
    htmls = list(zip(cnblogs_spider.urls,htmls))
    for url,html in htmls:
        print(url,len(html))

#parse
with concurrent.futures.ThreadPoolExecutor() as pool:
    futures = {}
    for url,html in htmls:
        future = pool.submit(cnblogs_spider.parse,html)
        futures[future] = url
    
    #for future,url in futures.items():
    #    print(url,future.result())
    for future in concurrent.futures.as_completed(futures):
        url = futures[future]
        print(url,future.result())
